﻿
$("#heightexpno").click(function(){
    $("#heightexpdiv").toggle(200);
});
//铺路推荐
var tjcurrentIndex=1;
var jycurrentIndex=1;
var zhncurrentIndex=1;
var quecurrentIndex=1;

var tjover=0;//推荐接口数据状态 0有数据 1没数据
var jyover=0;//经验接口数据状态
var zhnover=0;//召唤你接口数据状态
var queover=0;//召唤你接口数据状态
var pageSize=10;//一页显示几条新闻
//var newsnum=0;//第几条新闻
var readyover=0;//控制页面滚动0正常 1加载中

//时间 几天前 几分钟前
function getDateTimeStamp(dateStr){
    dateStr=dateStr.match(/[0-9\-T\:]+/)[0].replace(/T/g,' ');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){ result="刚刚";return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}

document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                console.log("没有填信息")
            }else{
                location.href="searchdetail.html?searchKey="+word;
            }
        }
    }
};

//召唤你页面  //按钮
var expbtn=document.getElementById("expbtn");  //经验
var askyou=document.getElementById("askyou");   //召唤你
var quebtn=document.getElementById("quebtn"); //问题
var explist=document.getElementById("explist");//经验
var askyoulist=document.getElementById("askyoulist");//召唤你
var quelist=document.getElementById("quelist"); //问题
var loca=location.href;

askyou.onclick=function(){
    $.cookie("pulupagescroll","");//当前滚动距离
    $.cookie("pulupagepage","");//当前显示页面
    $.cookie("tjcurrentIndex","");//推荐数据页码
    $.cookie("zhncurrentIndex","");//召唤你数据页码
    $.cookie("jycurrentIndex","");//经验 铺路数据页码
    $.cookie("quecurrentIndex","");//问题 铺路数据页码
    location.href="questionlistzhn.html";
};
expbtn.onclick=function(){
    $.cookie("pulupagescroll","");//当前滚动距离
    $.cookie("pulupagepage","");//当前显示页面
    $.cookie("tjcurrentIndex","");//推荐数据页码
    $.cookie("zhncurrentIndex","");//召唤你数据页码
    $.cookie("jycurrentIndex","");//经验 铺路数据页码
    $.cookie("quecurrentIndex","");//问题 铺路数据页码
    location.href="questionlistjy.html";
};

quebtn.onclick=function(){
    $.cookie("pulupagescroll","");//当前滚动距离
    $.cookie("pulupagepage","");//当前显示页面
    $.cookie("tjcurrentIndex","");//推荐数据页码
    $.cookie("zhncurrentIndex","");//召唤你数据页码
    $.cookie("jycurrentIndex","");//经验 铺路数据页码
    $.cookie("quecurrentIndex","");//问题 铺路数据页码
    location.href="questionlisttw.html";
};

//
//var quick=document.getElementsByClassName("quick")[0];
//var quicklist=document.getElementsByClassName("quicklist")[0];
//quick.onclick=function(){
//    if(quicklist.style.display==="block"){
//        quicklist.style.display="none";
//    }else if(quicklist.style.display==="none"){
//        quicklist.style.display="block";
//    }
//};
//付费分享
var sharepay=document.getElementsByClassName("sharepay");
var sharepaymob=document.getElementsByClassName("sharepaymob")[0];
var cancel3=document.getElementsByClassName("cancel3")[0];
var sharepayword=document.getElementsByClassName("sharepayword")[0];
var askpayword=document.getElementsByClassName("askpayword")[0];
var modalbg=document.getElementsByClassName("modal_bg2")[0];
for(var sh=0;sh<sharepay.length;sh++){
    sharepay[sh].onclick=function(){
        modalbg.style.display="block";
        sharepaymob.style.display="block";
        sharepayword.style.display="block";
        askpayword.style.display="none";
    }
}
cancel3.onclick=function(){
    if(modalbg.style.display=="block"&&sharepaymob.style.display=="block"){
        modalbg.className+=' animate_out';
        sharepaymob.className+=' animate_out';
    }
    timer=setTimeout(changeclass3,100);
};
//付费充值跳转
okgobtn.onclick=function(){
    modalbg.className+=' animate_out';
    sharepaymob.className+=' animate_out';
    location.href="scoredetial.html";
};
function changeclass3(){
    modalbg.className='modal_bg modal_bg';
    sharepaymob.className='action_menu_container sharepaymob';
    clearTimeout();
    timer2=null;
    changedisplay3();
};
function changedisplay3(){
    modalbg.style.display="none";
    sharepaymob.style.display="none";
};
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
//付费回答
var askpay=document.getElementsByClassName("askpay");
for(var as=0;as<askpay.length;as++){
    askpay[as].onclick=function(){
        modalbg.style.display="block";
        sharepaymob.style.display="block";
        sharepayword.style.display="none";
        askpayword.style.display="block";
    }
}
cancel3.onclick=function(){
    if(modalbg.style.display=="block"&&sharepaymob.style.display=="block"){
        modalbg.className+=' animate_out';
        sharepaymob.className+=' animate_out';
    }
    timer=setTimeout(changeclass3,100);
};

var id;
if($.cookie("MYID")){id=$.cookie("MYID")};
var returnurl=encodeURIComponent("http://www.pulu.com/weixin/questionlistjy.html"); //同意后跳转页面
//发高额
function gotoheiexp(data){
    var eid=data.dataset.keyword;
    var e=arguments.callee.caller.arguments[0]||event;
    if(e&&e.stopPropagation()){
        e.stopPropagation();
    }else if(window.event){
        window.event.cancelBubble = true;
    }
    //if(is_weixn()){
    $.cookie("expkeyword",eid);
    location.href="http://www.pulu.com/weixin/sendexpg.html";
    //}
    //else{
    //    location.href="http://www.pulu.com/sendexpgpc.html?id="+id+"&keyword="+eid;
    //}
}
//跳转方法
function hrefgo(e){
    var url= e.dataset.href;
    var pageid=e.dataset.page;
    var euserid=e.dataset.euser;
    var eid=url.match(/[0-9]+/)[0];

    $.cookie("pulupagescroll",$(window).scrollTop());//当前滚动距离
    $.cookie("pulupagepage",pageid);//当前显示页面
    $.cookie("jycurrentIndex",jycurrentIndex);//经验 铺路数据页码
    //清除转发者信息 防止返回信息保存
    $.cookie("shareUserId","");
    $.cookie("fromuser","");
    if(e.dataset.shareuserid){
        //shareuser="&shareuser="+e.dataset.shareuserid;
        $.cookie("shareUserId",e.dataset.shareuserid);
    }
    location.href=url;
}
//所有页面方法
//高德地图获取坐标
var lot,lat,
    //distance="&distance=10";
    distance="";
function allftn(){
    function hrefgo(e){
        var url= e.dataset.href;
        var pageid=e.dataset.page;
        var euserid=e.dataset.euser;
        var eid=url.match(/[0-9]+/)[0];

        $.cookie("pulupagescroll",$(window).scrollTop());//当前滚动距离
        $.cookie("pulupagepage",pageid);//当前显示页面
        $.cookie("jycurrentIndex",jycurrentIndex);//经验 铺路数据页码
        //清除转发者信息 防止返回信息保存
        $.cookie("shareUserId","");
        $.cookie("fromuser","");
        if(e.dataset.shareuserid){
            //shareuser="&shareuser="+e.dataset.shareuserid;
            $.cookie("shareUserId",e.dataset.shareuserid);
        }
        location.href=url;
    }
    function mapftn(jycurrentIndex,pageSize){
        if(lot){
            jy(jycurrentIndex,pageSize,distance);
        }else{
            var map, geolocation;
//加载地图，调用浏览器定位服务
            map = new AMap.Map('mapplace', {
                resizeEnable: true
            });
            map.plugin('AMap.Geolocation', function() {
                geolocation = new AMap.Geolocation({
                    enableHighAccuracy: true,//是否使用高精度定位，默认:true
                    noIpLocate:0,
                    GeoLocationFirst:true,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
                    convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                    timeout: 15000          //超过15秒后停止定位，默认：无穷大
                });
                map.addControl(geolocation);
                geolocation.getCurrentPosition();
                AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
                AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
            });
//解析定位结果
            function onComplete(data) {
                //var shiname=data.formattedAddress.split("省")[1].split("市")[0]+"市";

                //console.log(data.position);
                lot= (data.position.lng);
                lat=(data.position.lat);
                jy(jycurrentIndex,pageSize,distance);
            }
//解析定位错误信息
            function onError(data) {
                //jy(jycurrentIndex,pageSize);
                $("#waiting1").remove();
                $("#nonews1").css("display","block");
                $("#nonews1").html("定位失败");
            }
        }
    }
    //附近经验数据url:expnearlyurl+lot+"&lat="+lat+"&distance="+distance+"&userId="+id+"&currentIndex="+jycurrentIndex+"&pageSize="+pageSize,
    function jy(jycurrentIndex,pageSize,distance){
        console.log("执行");
        //var lot=118.825222,lat=32.027218;//118.77807441,32.0572355
        if(jyover===0){
            $.ajax({
                type:"get",
                datatype:"json",
                url:expnearlyurl+lot+"&lat="+lat+distance+"&userId="+id+"&currentIndex="+jycurrentIndex+"&pageSize="+pageSize,
                success:function(d){
                    var ulid="#explist";
                    if(d.Message==="没有数据"||(d.Data&&d.Data.length===0)||!d.Data){
                        jyover=1;
                        readyover=0;
                        $("#waiting1").css("display","none");
                        $("#nonews1").css("display","block");
                    }else{
                        if(d.Data.length<pageSize){
                            //$("#waiting1").remove();
                            jyover=1;
                            readyover=0;
                            $("#waiting1").css("display","none");
                            $("#nonews1").css("display","block");
                        }
                        var fortime=0;//循环次数
                        for(var i= 0,r=d.Data.length;i<r ;i++){
                            fortime++;
                            d.Data[i].index=i;
                            if(d.Data[i].title&&d.Data[i].title.length>0){
                                //匿名
                                var unick="";
                                if(d.Data[i].questionUserNick){
                                    if(d.Data[i].ishidename==1){
                                        unick="<a>匿名</a>";
                                    }else{
                                        unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].nick+"</a>";
                                    }
                                }
                                //头像
                                var uimgword="";
                                if(d.Data[i].questionUserAva){
                                    if(d.Data[i].ishidename==1){
                                        uimgword="<a href='javascript: ;'><img onclick='gohrefftnerr(this)' class='profile_photo_img' src='../img/af8.png'></a>";
                                    }else{
                                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.Data[i].questionUserAva+"'></a>";
                                    }
                                }else{
                                    if(d.Data[i].ishidename==1){
                                        uimgword="<a href='javascript: ;'><img onclick='gohrefftnerr(this)' class='profile_photo_img' src='../img/af8.png'></a>";
                                    }else{
                                        uimgword="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png'></a>";
                                    }
                                    //uimgword="<img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png'>";
                                };
                                var otherid=d.Data[i].userId;
                                //时间
                                var tim="";
                                if(d.Data[i].ctime){
                                    tim=getDateDiff(getDateTimeStamp(d.Data[i].ctime));
                                }
                                var testtime=getDateTimeStamp(d.Data[i].ctime);
                                //是不是推荐
                                var tuijianword="";
                                var moneysty='style="position:absolute;right:0;"';
                                if(d.Data[i].isStranger===1){
                                    tuijianword="<div class='tuijian'></div>";
                                    moneysty='style="position:absolute;right:64px;"';
                                }
                                //有没有钱
                                var money="";
                                if(d.Data[i].score>0){
                                    var score= parseFloat(d.Data[i].score)/100;
                                    money="<span class='havemy' "+moneysty+">¥ "+score+"</span>";
                                }
                                //有没有图片
                                var haveimg="";
                                if(d.Data[i].imgcount>0){
                                    haveimg="<span class='isheighlogo haveimg'></span>"
                                }
                                //if(d.Data[i].imgcount>0){
                                //    haveimg="(图)"
                                //}

                                //是不是转换
                                var isconvert="";
                                if(d.Data[i].isconvert&&d.Data[i].isconvert===1){
                                    isconvert="(悬赏完成转经验)"
                                }
                                //判断是否有点赞者
                                var userimg="";//保存头像代码段 修改评星
                                //评星
                                var starlen=0;
                                if(d.Data[i].star!==0){
                                    var strnum=(d.Data[i].star).toString();
                                    if(strnum.length===3){
                                        var lastnum=parseFloat(strnum.substring(strnum.length-1));
                                        //尾数在4~6之间
                                        if(lastnum>=4&&lastnum<=6){
                                            starlen=strnum.substring(strnum.length-1,0)+5;
                                        }else if(lastnum<4){
                                            starlen=strnum.substring(0,1);
                                        }else if(lastnum>6){
                                            starlen=parseFloat(strnum.substring(0,1))+1;
                                        }
                                    }else{
                                        starlen=d.Data[i].star;
                                    }

                                }
                                userimg="<div class='starimg'><i style='width:"+parseFloat(starlen)*20+"%;'></i></div>";
                                //我也说说
                                var gotoheiexp="<div class='gotoheiexp' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+">我也来说说：有关</div>";
                                //高额
                                var isheilogo="";
                                if(d.Data[i].isexphigh===1||d.Data[i].isexphigh===2){
                                    isheilogo="<span class='isheighlogo'></span>";
                                }
                                //标题
                                //var tit=codetoface(d.Data[i].title)+"(还有"+d.Data[i].wordcount+"字)";
                                var tit=codetoface(d.Data[i].title);
                                var count=0;
                                if(d.Data[i].count){
                                    count=d.Data[i].count;
                                }
                                //昵称
                                var unick="";
                                if(d.Data[i].ishidename===1){
                                    unick="<a>匿名</a>";
                                }else{
                                    unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].questionUserNick+"</a>";
                                }
                                //位置
                                var location="";
                                if(d.Data[i].pululocation){
                                    location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                                }
                                //关键词
                                var keywordnor;
                                var keyword="<span class='keywordtit' style='display:none;'>关键词：</span>";
                                if(d.Data[i].keywords){
                                    keywordnor=d.Data[i].keywords.split(",");
                                    for(var a=0;a<keywordnor.length;a++){
                                        keyword+="<span>"+keywordnor[a]+"</span>";
                                    }
                                }
                                if(!d.Data[i].shareUserId){
                                    if(!tim){
                                        tim="刚刚";
                                    }
                                    $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' data-money='"+d.Data[i].score+"' onclick='hrefgo(this)' data-page='"+ulid+"' data-isheight='"+d.Data[i].isexphigh+"' data-euser='"+d.Data[i].questionUserId+"' data-href='http://www.pulu.com/weixin/shareexppage.html?eid="+d.Data[i].id+"#fromuser="+id+"'><div class='feed_item feed_type_question'>"+tuijianword+"<div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+isheilogo+"</span><div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2><a class='question_link'>"+isconvert+tit+"("+d.Data[i].wordcount+"字)"+haveimg+"</a></h2><div class='upviter'>"+userimg+"</div><div class='ActionBar Question'>"+location+"<div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>浏览 "+count+"&nbsp;&nbsp;&nbsp;付费 "+d.Data[i].payCount+"</a> </div> </div></div>"+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+"><div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div>");

                                }
                                //转发
                                else if(d.Data[i].shareUserId&&d.Data[i].shareUserId.length>0){
                                    var des="";
                                    if(d.Data[i].des){
                                        des=codetoface(d.Data[i].des);
                                    }
                                    var count=0;
                                    if(d.Data[i].count){
                                        count=d.Data[i].count;
                                    }
                                    var sharetim=getDateDiff(getDateTimeStamp(d.Data[i].shareTime.match(/[0-9\-T\:]+/)[0]));
                                    var tim=getDateDiff(getDateTimeStamp(d.Data[i].ctime.match(/[0-9\-T\:]+/)[0]));
                                    var unick="";
                                    if(d.Data[i].ishidename===1){
                                        unick="<a>匿名</a>";
                                    }else{
                                        unick="<a href='otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'>"+d.Data[i].questionUserNick+"</a>";
                                    }
                                    var location="";
                                    if(d.Data[i].pululocation){
                                        location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.Data[i].pululocation+"</span></div>"
                                    }
                                    //转发调整金额样式
                                    var moneysty='style="position:absolute;right:0;"';
                                    money="<span class='havemy' "+moneysty+">¥ "+score+"</span>";

                                    var  peopleurl="'otherpeoplepage.html?otherid="+d.Data[i].questionUserId+"'";
                                    $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' data-money='"+d.Data[i].score+"' onclick='hrefgo(this)' data-page='"+ulid+"' data-isheight='"+d.Data[i].isexphigh+"' data-euser='"+d.Data[i].questionUserId+"' data-href='http://www.pulu.com/weixin/shareexppage.html?eid="+d.Data[i].id+"#fromuser="+id+"' data-shareuserid='"+d.Data[i].shareUserId+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+ d.Data[i].shareUserNick+"·转发</span>·"+sharetim+"</div><div class='info_wrapper' style='margin-left:10px;margin-top:7px;'> <div class='info'> <span class='feed_item_answer_user'>"+des+"</span> </div> </div> <div class='borderbox'><div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+isheilogo+"</span> <div class='ContentFooter'>"+tim+"</div></div></div></div>"+"<h2><a class='question_link'>"+isconvert+tit+"("+d.Data[i].wordcount+"字)"+haveimg+"</a></h2><div class='upviter'>"+userimg+"</div><div class='ActionBar Question'>"+location+"<div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>浏览 "+count+"&nbsp;&nbsp;&nbsp;付费 "+d.Data[i].payCount+"</a> </div></div></div>"+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-keyword="+d.Data[i].id+"><div class='QuestionTopics has_topics'>"+gotoheiexp+keyword+"</div></div></div></div></div>")
                                }
                            };
                            //页面滚动判断
                            if("#explist"===$.cookie("pulupagepage")&&fortime===r&&$.cookie("pulupagescroll")&&parseFloat($.cookie("pulupagescroll"))>0){
                                $(window).scrollTop(parseFloat($.cookie("pulupagescroll")));
                                readyover=0;
                                $.cookie("pulupagepage","");//清除页面ID
                                $.cookie("pulupagescroll","");//当前滚动距离
                                $.cookie("pulupagepage","");//当前显示页面
                                $.cookie("tjcurrentIndex","");//推荐数据页码
                                $.cookie("zhncurrentIndex","");//召唤你数据页码
                                $.cookie("jycurrentIndex","");//经验 铺路数据页码
                            };
                            if(fortime==r){
                                readyover=0;
                            }
                        };
                    }
                }
            })
        };
    }
    $().ready(function(){
        if($.cookie("pulupagepage")){
            $("#explist div.addlistplace div").remove();
            var pagelist=document.getElementsByClassName("HomeMainFeed");
            var navlist=document.getElementsByClassName("HeaderSwitcherItem");
            readyover=1;//控制页面滚动
            //经验
            if($.cookie("jycurrentIndex")!=="NaN"){
                jypageSize=parseFloat($.cookie("jycurrentIndex"))*10;
            }else{
                jypageSize=10;
            }
            //jy(1,jypageSize);
            mapftn(1,jypageSize);

            jycurrentIndex=parseFloat($.cookie("jycurrentIndex"));
        }
        else{
            if(id){
                mapftn(jycurrentIndex,pageSize);
                //jy(jycurrentIndex,pageSize);
            }
        }
    });
    var upanddown=127;
    $(window).scroll(function(){
        $(".quicklist").css("display","none");
        $("#refreshbtn").css("display","block");
        var mainheight=$(".home_feed").height();
        var windowheight=$(window).height();
        var what=$(".home_feed").offset().top;
        var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
        var cz=windowheight-mainheight+50;
        if(chajuli<cz&&readyover===0){
            if(document.getElementById("explist").style.display=="block"&&jyover==0){
                jycurrentIndex++;
                readyover=1;
                //jy(jycurrentIndex,pageSize);
                mapftn(jycurrentIndex,pageSize);
            }
        }
        //导航条隐藏显示
        //console.log(chajuli);
        //var a2=chajuli;
        //if(a2<upanddown){
        //    upanddown=a2;
        //    //向下滚动
        //    if(chajuli<36){
        //        $(".fixed_header").css({"position":"fixed","top":"-88px"});
        //        $(".wrapper.home_feed").css({"margin-top":"44px"});
        //        $("#page_wrapper").css("margin-top","44px");
        //    }
        //}
        //else{
        //    upanddown=a2;
        //    //向上滚动
        //    if(0<chajuli){
        //        $(".fixed_header").css({"position":"absolute","top":"0px"});
        //        $(".wrapper.home_feed").css({"margin-top":"0"});
        //        $("#page_wrapper").css("margin-top","127px");
        //    }
        //}
    });
    //刷新页面
    $("#refreshbtn").click(function(){
        jycurrentIndex=1;
        $("#waiting1").css("display","block");
        $("#nonews1").css("display","none");
        $(".fixed_header").css({"position":"absolute","top":"0px"});
        $(".wrapper.home_feed").css({"margin-top":"0"});
        $("#page_wrapper").css("margin-top","127px");
        $("#explist .addlistplace div").remove();
        mapftn(jycurrentIndex,pageSize);
    });
    //刷新页面方法 选择地址使用
    function refresh(){
        jycurrentIndex=1;
        $("#waiting1").css("display","block");
        $("#nonews1").css("display","none");
        //$(".fixed_header").css({"position":"absolute","top":"0px"});
        //$(".wrapper.home_feed").css({"margin-top":"0"});
        //$("#page_wrapper").css("margin-top","127px");
        $("#explist .addlistplace div").remove();
        jy(jycurrentIndex,pageSize,distance);
    }
    //选择地址
    //全部
    $("#alldist").click(function(){
        distance="";
        $("#alldist").prop("class","HeaderSwitcherItem is_active");
        $("#fimdist").prop("class","HeaderSwitcherItem");
        $("#twkdist").prop("class","HeaderSwitcherItem");
        $("#fikdist").prop("class","HeaderSwitcherItem");
        $("#tekdist").prop("class","HeaderSwitcherItem");
        if(lot){
            jyover=0;
            refresh();
        }
    });
    //500米
    $("#fimdist").click(function(){
        distance="&distance=0.5";
        $("#alldist").prop("class","HeaderSwitcherItem");
        $("#fimdist").prop("class","HeaderSwitcherItem is_active");
        $("#twkdist").prop("class","HeaderSwitcherItem");
        $("#fikdist").prop("class","HeaderSwitcherItem");
        $("#tekdist").prop("class","HeaderSwitcherItem");
        if(lot){
            jyover=0;
            refresh();
        }
    });
    //2公里
    $("#twkdist").click(function(){
        distance="&distance=2";
        $("#alldist").prop("class","HeaderSwitcherItem");
        $("#fimdist").prop("class","HeaderSwitcherItem");
        $("#twkdist").prop("class","HeaderSwitcherItem is_active");
        $("#fikdist").prop("class","HeaderSwitcherItem");
        $("#tekdist").prop("class","HeaderSwitcherItem");
        if(lot){
            jyover=0;
            refresh();
        }
    });
    //5公里
    $("#fikdist").click(function(){
        distance="&distance=5";
        $("#alldist").prop("class","HeaderSwitcherItem");
        $("#fimdist").prop("class","HeaderSwitcherItem");
        $("#twkdist").prop("class","HeaderSwitcherItem");
        $("#fikdist").prop("class","HeaderSwitcherItem is_active");
        $("#tekdist").prop("class","HeaderSwitcherItem");
        if(lot){
            jyover=0;
            refresh();
        }
    });
    //10公里
    $("#tekdist").click(function(){
        distance="&distance=10";
        $("#alldist").prop("class","HeaderSwitcherItem");
        $("#fimdist").prop("class","HeaderSwitcherItem");
        $("#twkdist").prop("class","HeaderSwitcherItem");
        $("#fikdist").prop("class","HeaderSwitcherItem");
        $("#tekdist").prop("class","HeaderSwitcherItem is_active");
        if(lot){
            jyover=0;
            refresh();
        }
    });
}
$(document).ready(function(){
    if(is_weixn()){
        if($.cookie("wxopenid")){
            //=======================================================
            //从登录页返回有openid没有id
            if($.cookie("MYID")){
                allftn();
            }
            else{
                location.href="login.html";
            }
            //=======================================================
        }
        else{
            //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
            var reg=new RegExp("code=[a-zA-Z0-9]*");
            if(window.location.href.match(reg)){
                var code=window.location.href.match(reg);
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){
                        var dat=data;
                        $.cookie("wxod",dat);
                        //发请求获取用户的id
                        $.ajax({
                            type:"GET",
                            url:getwxopenidurl+dat,
                            success:function(d){
                                //如果没有用户id 则证明用户是第一次登陆 保存openid跳转至登录页面
                                if(!d.Data){
                                    $.cookie("wxopenid",dat);

                                    location.href="login.html";
                                }else if(d.Data&&d.Data.userId){
                                    $.cookie("wxopenid",d.Data.openId);
                                    $.cookie("MYID",d.Data.userId);
                                    id=d.Data.userId;
//=======================================================================
                                    allftn();
//=======================================================================
                                }
                                //如果有用户ID 就把cookies里的用户id替换成获取到的id  在这里控制跳转提示框
                            }
                        })
                    }
                })
            }else{
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            }
        }
    }
    else{
        allftn();
    }
});